import { Body, Controller, Get, Post, UsePipes } from '@nestjs/common';
import { PermissionRuleModelService } from 'src/model/permission-rule-model/permission-rule-model.service';
import dtoValidationPipe from 'src/pipe/Dto.pipe';
import { errorReturn, successReturn } from 'src/utils';
import { AddDto } from './dto';

@Controller('permission')
export class PermissionController {
    constructor(
        private model:PermissionRuleModelService
    ) {
        
    }

    @Get()
    async permissions() {
        return []
    }

    @Post('add')
    @UsePipes(dtoValidationPipe())
    async addMerchant(@Body() dto:AddDto) {
       try {
            if((await this.model.isExistsByWhere({code : dto.code}))) return errorReturn('已存在相同的编码')
            await this.model.insert(dto)
            return successReturn()
       } catch (error) {
           
       }

       return errorReturn()
    }
}
